<template>
	<view>
		<view class="TaskBg">
			<view class="TaskTitleBg">
				<text class="TaskTitle">学生信息</text>
			</view>
			<view class="TaskList" v-if="StudentInfo">
				<text class="Task">姓名：<text>{{StudentInfo.name}}</text></text>
				<text class="Task">学号：<text>{{StudentInfo.studentNo}}</text></text>
				<text class="Task">系部：<text>{{StudentInfo.departmentName}}</text></text>
				<text class="Task">宿舍：<text>{{StudentInfo.buildName}}</text></text>
			</view>
			<view v-for="item in PowerList" :key="item.id">
				<button class="GotoProc" @click="CompleteTask(item.id)">
					<text>》》{{item.procName}}《《</text>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				recordTime:'',
				StudentInfo: null,
				PowerList: null
			}
		},
		onLoad(e) {
			let {
				id = '',
				recordTime=''
			} = e;
			this.id = e.studentId;
			this.recordTime=e.recordTime;
			console.log("进入学生页面,传过来的学生Id为", this.id);
			this.GetStudentInfo();
			this.InitPowerList();
		},
		methods: {
			GetStudentInfo() {
				uni.request({
					url: this.$httpUrl + '/QrCodeProc/GetStudentDetail',
					// POST/GET
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						studentId: this.id
					},
					success: success => {
						console.log("获取学生详情数据", success.data);
						console.log(success.data.code);
						if (success.data.code === 200) {
							this.StudentInfo = success.data.data;
							console.log("this.StudentInfo", this.StudentInfo);
							// this.TaskInfo = _TaskInfo;
						}
					},
					fail: (fail) => {
						console.log(fail.data);
						// 失败回调
					}
				});
			},
			InitPowerList() {
				var Admindata = uni.getStorageSync('admin');
				console.log(Admindata.admin.processList);
				this.PowerList = Admindata.canProcessList;
				console.log(this.PowerList);
			},
			CompleteTask(id = '') {
				var Admindata = uni.getStorageSync('admin');
				console.log("studentNo",this.StudentInfo.id);
				console.log("processId",id);
				console.log("PersonId",Admindata.admin.id);
				console.log("recordTime",this.recordTime);
				uni.request({
					url: this.$httpUrl + '/QrCodeProc/CompleteTask',
					// POST/GET
					method: 'POST',
					// header: {
					// 	'content-type': 'application/x-www-form-urlencoded'
					// },
					data: {
						studentNo: this.StudentInfo.studentNo,
						processId: id,
						PersonId: Admindata.admin.id.toString(),
						RecordTime:this.recordTime
					},
					success: success => {
						console.log("完成任务回调", success.data);
						console.log(success.data.code);
						if(success.data.code===200)
						{
							uni.showToast({
								title: '任务完成！'
							});
						}
						else{
							uni.showToast({
								title:  success.data.message
							});
						}
					},
					fail: (fail) => {
						console.log(fail);
					}
				});
			}
		}

	}
</script>

<style>
	.TaskBg {
		position: absolute;
		line-height: 8vh;
		height: 100vh;
		width: 90vw;
		left: 5vw;
		top: 10vh;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		box-shadow: 2rpx 2rpx 10rpx #27347d;
	}

	.TaskTitleBg {
		height: 10vh;
	}

	.TaskTitle {
		text-align: center;
		display: block;
		color: white;
		background: #fdbb59;
		padding: 0.2rem;
		font-size: 1rem;
		height: 5vh;
		line-height: 5vh;
		width: auto;
		border-radius: 1vw;
		margin: 1vh 5vw;
		box-shadow: 2rpx 2rpx 10rpx #d49b4b;
	}

	.TaskList {
		height: auto;
	}

	.Task {
		margin-left: 10vw;
		float: left;
		width: 70vw;
		height: 7vh;
	}

	.GotoProc {
		margin: 0vh 5vw 1vh 5vw;
		width: 78vw;
		text-align: center;
	}
</style>
